<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>积分记录管理 - MeetUp 管理后台</title>

    {% load static %}
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <style>
        :root {
            --sidebar-width: 250px;
            --header-height: 60px;
            --primary-color: #FF8C42;
            --secondary-color: #FFB347;
            --accent-color: #FFD166;
            --light-color: #f8f9fa;
            --dark-color: #2D3047;
            --text-color: #333333;
            --bg-color: #FFF9F2;
        }

        .card {
            border: none;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
            margin-bottom: 20px;
            overflow: hidden;
            background-color: white;
        }

        .stat-card {
            text-align: center;
            padding: 25px 15px;
            position: relative;
        }

        .stat-card i {
            font-size: 2.5rem;
            margin-bottom: 15px;
            color: var(--primary-color);
            background: rgba(255, 140, 66, 0.1);
            width: 70px;
            height: 70px;
            line-height: 70px;
            border-radius: 50%;
            display: inline-block;
        }

        .stat-card .number {
            font-size: 2.2rem;
            font-weight: bold;
            color: var(--dark-color);
            margin: 10px 0;
        }

        .points-earned { color: #28a745; font-weight: bold; }
        .points-used { color: #dc3545; font-weight: bold; }

        .badge-activity_join { background-color: #007bff; }
        .badge-activity_review { background-color: #17a2b8; }
        .badge-discussion_post { background-color: #28a745; }
        .badge-discussion_comment { background-color: #20c997; }
        .badge-daily_signin { background-color: #ffc107; color: #212529; }
        .badge-points_exchange { background-color: #6f42c1; }
        .badge-admin_adjust { background-color: #fd7e14; }
        .badge-invite_friend { background-color: #e83e8c; }
    </style>
</head>
<body>
    <!-- 侧边栏和顶部导航栏 -->
    <!-- 这里省略重复的侧边栏和导航栏代码 -->

    <div id="content">
        <nav class="navbar navbar-expand navbar-light bg-white">
            <div class="container-fluid">
                <button type="button" id="sidebarCollapse" class="btn btn-primary">
                    <i class="bi bi-list"></i>
                </button>
                <ul class="navbar-nav ms-auto">
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown">
                            <i class="bi bi-person-circle"></i> {{ request.user.username }}
                        </a>
                        <ul class="dropdown-menu">
                            <li><a class="dropdown-item" href="/user/person_center/"><i class="bi bi-person"></i> 个人资料</a></li>
                            <li><a class="dropdown-item" href="#"><i class="bi bi-gear"></i> 设置</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="/user/logout/"><i class="bi bi-box-arrow-right"></i> 退出</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </nav>

        <div class="container-fluid p-4">
            <h2 class="mb-4">积分记录管理</h2>

            <!-- 统计卡片 -->
            <div class="row mb-4">
                <div class="col-md-3">
                    <div class="card stat-card">
                        <i class="bi bi-arrow-up-circle"></i>
                        <div class="number">{{ total_earned }}</div>
                        <div class="label">总获得积分</div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="card stat-card">
                        <i class="bi bi-arrow-down-circle"></i>
                        <div class="number">{{ total_used }}</div>
                        <div class="label">总使用积分</div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="card stat-card">
                        <i class="bi bi-graph-up"></i>
                        <div class="number">{{ net_points }}</div>
                        <div class="label">净积分</div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="card stat-card">
                        <i class="bi bi-clock-history"></i>
                        <div class="number">{{ page_obj.paginator.count }}</div>
                        <div class="label">总记录数</div>
                    </div>
                </div>
            </div>

            <!-- 筛选栏 -->
            <div class="card">
                <div class="card-body">
                    <form class="row g-3" method="get">
                        <div class="col-md-3">
                            <select class="form-select" name="source_type">
                                <option value="">所有来源</option>
                                {% for source_value, source_name in source_choices %}
                                    <option value="{{ source_value }}" {% if source_type == source_value %}selected{% endif %}>
                                        {{ source_name }}
                                    </option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="col-md-3">
                            <input type="text" class="form-control" name="user_id" value="{{ user_id }}" placeholder="用户ID">
                        </div>
                        <div class="col-md-3">
                            <select class="form-select" name="date_range">
                                <option value="">所有时间</option>
                                <option value="today" {% if date_range == 'today' %}selected{% endif %}>今日</option>
                                <option value="week" {% if date_range == 'week' %}selected{% endif %}>最近一周</option>
                                <option value="month" {% if date_range == 'month' %}selected{% endif %}>最近一月</option>
                            </select>
                        </div>
                        <div class="col-md-3">
                            <button type="submit" class="btn btn-primary w-100">筛选</button>
                        </div>
                    </form>
                </div>
            </div>

            <!-- 积分记录列表 -->
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="card-title mb-0">积分记录</h5>
                    <span class="text-muted">共 {{ page_obj.paginator.count }} 条记录</span>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>用户</th>
                                    <th>积分变化</th>
                                    <th>来源</th>
                                    <th>描述</th>
                                    <th>来源ID</th>
                                    <th>时间</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for record in page_obj %}
                                <tr>
                                    <td>
                                        <div class="d-flex align-items-center">
                                            {% if record.user.avatar %}
                                                <img src="{{ record.user.avatar.url }}" alt="{{ record.user.username }}" style="width: 32px; height: 32px; border-radius: 50%; object-fit: cover; margin-right: 10px;">
                                            {% else %}
                                                <div style="width: 32px; height: 32px; background: #f8f9fa; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-right: 10px;">
                                                    <i class="bi bi-person text-muted"></i>
                                                </div>
                                            {% endif %}
                                            <div>
                                                <strong>{{ record.user.username }}</strong>
                                                <br>
                                                <small class="text-muted">ID: {{ record.user.id }}</small>
                                            </div>
                                        </div>
                                    </td>
                                    <td>
                                        {% if record.points > 0 %}
                                            <span class="points-earned">+{{ record.points }}</span>
                                        {% else %}
                                            <span class="points-used">{{ record.points }}</span>
                                        {% endif %}
                                    </td>
                                    <td>
                                        <span class="badge badge-{{ record.source_type }}">
                                            {{ record.get_source_type_display }}
                                        </span>
                                    </td>
                                    <td>{{ record.description }}</td>
                                    <td>
                                        {% if record.source_id %}
                                            <code>{{ record.source_id }}</code>
                                        {% else %}
                                            <span class="text-muted">-</span>
                                        {% endif %}
                                    </td>
                                    <td>{{ record.created_at|date:"Y-m-d H:i" }}</td>
                                </tr>
                                {% empty %}
                                <tr>
                                    <td colspan="6" class="text-center py-4">
                                        <i class="bi bi-clock-history display-4 text-muted"></i>
                                        <p class="mt-2 text-muted">暂无积分记录</p>
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>

                    <!-- 分页 -->
                    {% if page_obj.has_other_pages %}
                    <nav>
                        <ul class="pagination justify-content-center">
                            {% if page_obj.has_previous %}
                            <li class="page-item">
                                <a class="page-link" href="?page={{ page_obj.previous_page_number }}{% if source_type %}&source_type={{ source_type }}{% endif %}{% if user_id %}&user_id={{ user_id }}{% endif %}{% if date_range %}&date_range={{ date_range }}{% endif %}">上一页</a>
                            </li>
                            {% endif %}

                            {% for i in page_obj.paginator.page_range %}
                            <li class="page-item {% if page_obj.number == i %}active{% endif %}">
                                <a class="page-link" href="?page={{ i }}{% if source_type %}&source_type={{ source_type }}{% endif %}{% if user_id %}&user_id={{ user_id }}{% endif %}{% if date_range %}&date_range={{ date_range }}{% endif %}">{{ i }}</a>
                            </li>
                            {% endfor %}

                            {% if page_obj.has_next %}
                            <li class="page-item">
                                <a class="page-link" href="?page={{ page_obj.next_page_number }}{% if source_type %}&source_type={{ source_type }}{% endif %}{% if user_id %}&user_id={{ user_id }}{% endif %}{% if date_range %}&date_range={{ date_range }}{% endif %}">下一页</a>
                            </li>
                            {% endif %}
                        </ul>
                    </nav>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>